<?php
/**
 * 新闻资讯管理类
 * comfiger
 * 2016-8-28
 **/
namespace Mama\Model;
use Think\Model;
class NewsModel extends Model{
	//定义表名称
	protected $tableName = 'news';
	
	public function getNewsCount($where=array()){
		return $this->where($where)->count();
	}

	public function getNewsList($page, $where=array()){
		return $this->alias('news')
					->join('left join mama_shop as shop on news.shop_id = shop.shop_id')
					->where($where)
					->field('news.*, shop.title as shoptitle')
					->order('sort asc, newid desc')
					->page($page, C('PAGE_SIZE'))
					->select();
	}
	
	public function getNewsInfoById($id){
		return $this->where(array('newid' => $id))->find();
	}
	
	/**
	 * 发布新闻
	 **/
	public function addNewsInfo($data){
		return $this->data($data)->add();
	}
	
	/**
	 * 编辑新闻
	 **/
	public function editNewsInfo($newid, $data){
		return $this->where(array('newid' => $newid))->setField($data);
	}
	
	public function deleteNewsInfo($newid){
		return $this->where(array('newid' => $newid))->delete();
	}
}